
import requests
from jsonschema.validators import validate

# def test_01():
#     testjson = {
#         "code":"success",
#         "status":"yes",
#         "int":111
#     }
#
#     testdata = {
#       "type": "object",
#       "properties": {
#         "code": {
#           "type": "string"
#         },
#         "status": {
#           "type": "string"
#         },
#         "int": {
#           "type": "integer"
#         }
#       }
#     }
#
#     validate(instance=testjson, schema=testdata)

"""
def test_json():
    # 验证格式
    schema = {
  "type": "object",
  "properties": {
    "code": {
      "type": "string"
    },
    "errMsg": {
      "type": "string",
      "pattern":"\S+"
    },
    "data": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "userName": {
          "type": "string"
        },
        "password": {
          "type": "string"
        },
        "githubUrl": {
          "type": "string",
          "format": "uri"
        },
        "deleteFlag": {
          "type": "integer"
        },
        "createTime": {
          "type": "string",
          "format": "date-time"
        },
        "updateTime": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}

    # 发起请求
    url = "http://8.137.19.140:9090/user/getUserInfo"
    headers = {
        "user_token_header": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwidXNlck5hbWUiOiJ6aGFuZ3NhbiIsImV4cCI6MTc1NjU0MTA5OX0.-KG0dre1pyBiFY6ub6knft-X7_FNketq00Ds7TNiSKc"
    }
    r = requests.get(url=url, headers=headers)
    # 验证
    validate(r.json(), schema)
"""

